﻿; $(function () {
    $("#toolbar").ligerToolBar({
        items: [{
            text: '添加',
            icon: '',
            id: 'btnSave',
            click: function (parameters) {
                location.href = "/Links/Edit?tid=" + $("#Tid").val();
            }
        },
            {
                text: '编辑',
                icon: '',
                id: 'btnEdit',
                click: function (parameters) {
                    var rows = manager.getSelectedRows();
                    if (rows && rows.length == 1) {
                        var row = manager.getSelectedRow();
                        if (row && row.Id != "") {
                            //if (row.IsChecked == 1) {
                            //} else {
                            location.href = "/Links/Edit?Id=" + row.Id + "&?tid=" + $("#Tid").val();
                            // }
                        } else {
                            $.ligerDialog.warn('请选择单条记录');
                        }
                    } else {
                        $.ligerDialog.warn('请选择单条记录');
                    }
                }
            },
            {
                text: '删除',
                icon: '',
                id: 'btnDelete',
                click: function (parameters) {

                    var rows = manager.getSelectedRows();
                    if (rows && rows.length > 0) {
                        var ids = new Array();
                        $.each(rows, function () {
                            ids.push(this.Id);
                        });
                        $.ajax({
                            url: '/Links/DeleteLinks',
                            dataType: 'json',
                            type: 'post',
                            data: { ids: ids.join(",") },
                            traditional: true,
                            success: function (callback) {
                                if (callback) {
                                    $.ligerDialog.alert('删除成功', function (yes) {
                                        manager.loadData();
                                    });
                                }
                                else {
                                    $.ligerDialog.error('删除失败');
                                }
                            },
                            error: function (ex) {
                                $.ligerDialog.error('删除失败');
                            }
                        });
                    } else {

                    }


                }
            }]
    });


    var manager = $("#grid").ligerGrid({
        columns: [
            //{
            //    display: '序号',
            //    align: 'center',
            //    width: 50,
            //    minWidth: 50,
            //    render: function (item, i) {
            //        return (i + 1).toString();
            //    }
            //},
            { display: 'ID', name: 'Id', isSort: false, width: 40, align: 'left', hide: true },
            {
                display: '标题',
                align: 'left',
                width: 350,
                minWidth: 100,
                name: 'Title'
            },
            { display: '链接地址', name: 'Url', isSort: false, width: 300, align: 'left' },
            {
                display: '图片', name: 'ImgUrl', isSort: false, width: 300, align: 'left',
                render: function (rowdata, rowindex, value) {
                    var h = "";
                    if (value != "") {
                        h += "<img width='24' height='15'  src='" + value + "' alt ='图片'/>";
                    }

                    return h;
                }
            }],
        //rowHeight:44,
        width: '99.85%',
        height:
            '100%',
        heightDiff:
            -20,
        pageSizeOptions:
            [5, 10, 15, 20],
        pageSize: 15,
        //data: TreeDeptData,
        alternatingRow:
            false,
        url:
            "/Links/Links",
        headerRowHeight:
            26,
        checkbox: true,
        autoCheckChildren: false,
        dataAction: "server",
        rowAttrRender:
            function (item, index) {
                return "";
            },
        parms: [
            { name:'tid',value: $("#Tid").val() }
        ]
    }


);
    $("#pt").click(function () {
        manager.options.parms = [
            { name: 'wherestr', value: '123' }
        ];
        manager.options.newPage = 1;
        manager.loadData();
    });
});